﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.IO;

namespace IconManager.ObjectModel
{
	public class PackIcon : BaseIcon
	{
		internal static string PacksRootDirUrl = "/umbraco/plugins/IconManager/IconPacks/";

		/// <summary>
		/// Initializes a new instance of the <see cref="PackIcon"/> class.
		/// </summary>
		/// <param name="packName">Name of the pack.</param>
		/// <param name="fileName">Name of the file.</param>
		public PackIcon(string packName, string fileName)
		{			
			this.FileName = fileName;
			this.Url = PackIcon.PacksRootDirUrl + packName + "/" + this.FileName;
			this.PhysicalPath = HttpContext.Current.Server.MapPath(this.Url);
		}

		/// <summary>
		/// Activates this PackIcon by copying it into the Umbraco Icons folder
		/// </summary>
		/// <returns>true if the file was copied</returns>
		public bool Activate()
		{
			bool activated = false;
			
			if (this.Exists)
			{
				// check to see if there's an existing UmbracoIcon with the same filename
				UmbracoIcon umbracoIcon = new UmbracoIcon(this.FileName);
				if (!umbracoIcon.Exists)
				{
					this.File.CopyTo(Icons.UmbracoIconDir.FullName, false);
					activated = true;
				}
			}

			return activated;
		}
	}
}